class CategoriesController < ApplicationController
	
	include SortHelper
	
	helper_method :sort_options
	skip_before_filter :require_logged_in, only: [:index, :show]
	
	def index		
		@categories = Category.with_translations(I18n.locale)
			.order(sort_order('order_position', Category))
			.paginate(page: params[:page])
			.find_all_by_parent_id(nil)
	end
	
	def show
		@category = Category.find(params[:id])
		subcats, docs = @category.children
		
		subcats = subcats.order(sort_order('order_position', Category))
		docs = docs.search(params[:search]).order(sort_order('name',  Document))
		
		@elements = (subcats + docs).paginate(page: params[:page])
	end

	private 
	
	def sort_options
		AComposite.sort_options
	end
	
end
